package com.ruoyi.reservoir.controller;

import cn.dev33.satoken.annotation.SaIgnore;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.reservoir.domain.vo.TaskVo;
import com.ruoyi.reservoir.service.IInterpretationTaskService;
import com.ruoyi.system.service.ISysUserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Set;

@Slf4j
@SaIgnore
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/task")
public class InterpretationTaskController {

    private final ISysUserService userService;

    private final IInterpretationTaskService taskService;

    @GetMapping("list")
    public R<?> list(){

        SysUser user = userService.selectUserById(SecurityUtils.getUserId());
        log.info("user:{}", user);

        return R.ok(taskService.list());
    }

    /**
     * 解译管理-分页查询解译任务列表接口
     * @param pageNo
     * @param pageSize
     * @param plotType
     * @param field
     * @param sort
     * @return
     */
    @PostMapping("interpretationTaskList")
    public R<?> getInterpretationTaskList(@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                          @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                          @RequestParam(name = "plotType") String plotType,
                                          @RequestParam(name = "field", required = false) String field,
                                          @RequestParam(name = "sort", required = false) String sort){

        SysUser user = userService.selectUserById(SecurityUtils.getUserId());
        IPage<TaskVo> result = taskService.getInterpretationTaskList(pageNo, pageSize, plotType, field, sort, user.getUserId());

        return R.ok(result);
    }

    /**
     * 解译管理-批量任务提交接口
     * @param taskIdSet
     * @return
     */
    @PostMapping("taskSubmission")
    public R<?> taskSubmission(@RequestBody Set<String> taskIdSet){

        R<?> result = taskService.taskSubmission(taskIdSet);

        return result;
    }

}
